#!/usr/bin/python
# -*-coding:UTF-8 -*-

# ========================
# @Time  : 2021/2/18
# @Author: Sunny
# ========================

"""
定义一个User类：
属性：
    name:属性值只能是字符串
    age:属性值只能是int
    desc:属性值也只能是字符串
    skill:属性值只能是list类型

name属性不能被删除
skill属性如果没有添加，则返回None
"""

class User:
    def __setattr__(self, key, value):
        if key =='name':
            if isinstance(value,str):
                super().__setattr__(key,value)
            else:
                raise AttributeError('name is only str')
        elif key =='age':
            if isinstance(value,int):
                super().__setattr__(key,value)
            else:
                raise AttributeError('age is only int')
        elif key =='desc':
            if isinstance(value,str):
                super().__setattr__(key,value)
            else:
                raise AttributeError('desc is only str')
        elif key =='skill':
            if isinstance(value,list):
                super().__setattr__(key,value)
            else:
                raise AttributeError('skill is only list')

    def __delattr__(self, item):
        if item == 'name':
            raise AttributeError('name属性不能被删除')
        else:
            super().__delattr__(item)

    def __getattr__(self,item):
        if item=='skill':
            return None
        else:
            return super().__getattribute__(item)


s = User()
s.skill = ['python']
print(s.skill)

s.name = 'musen'
del s.name